package com.zhouyu.mybatis.demo;

import com.zhouyu.mybatis.demo.mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.mybatis.spring.annotation.MapperScan;

import java.io.IOException;
import java.io.InputStream;
@MapperScan
public class MyBaitsDemo {
	public static void main(String[] args) throws IOException {
		String resource = "mybatis.xml";
		InputStream inputStream = Resources.getResourceAsStream(resource);
		SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
		sqlSessionFactory.getConfiguration().addMapper(UserMapper.class);
		try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
			UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
			String result = userMapper.query();
			System.out.println(result);
		}
	}
}
